;define(function(require, exports, module) {
	var base = require("base");
	var router = require("../hash/pageRouter");
	
    var init = function(num){
        require("../leftMenu/leftMenu.css"),
        $("#leftMenu").html(require("../leftMenu/leftMenu.html"));
        $("#leftMenu").removeClass("none");
        num=num*1+1;
        initLeftMenu(num);
        initEvent();
        inquireCurrentOperationList();
    };
    var initEvent = function(){
    	$("ul .leftMenu-item").on("click",function(){
            var index = $(this).index("ul .leftMenu-item");
            $("ul .leftMenu-item").removeClass("leftMenu-active");
            $(this).addClass("leftMenu-active");
            $(this).parent().parent().addClass("leftMenu-open");
        });
        $("li a.leftMenu-dropdown-toggle").on("click",function(){
            $(this).parent().toggleClass("leftMenu-open");
        });
    };
    
    var initLeftMenu = function (num) {
    	var leftMenu = "#leftMenu"+num;
        $(leftMenu).removeClass('none');
    	switch (num){
    		case 1:
    			break;
    		case 2:
    			break;
    		case 3:
    			$("#blankInfo-manager").unbind("click").click(function(){
    				router.route("bankInfoManage/bankInfoList.html");
    			});
    			
    			$("#capital-manager").unbind("click").click(function(){
    				router.route("capitalManage/capitalList.html");
    			});
    			
    			$("#pledge-manager").unbind("click").click(function(){
    				router.route("capitalManage/pledgeParameterList.html");
    			});
    			
    			$("#pledgeEvaluation-manager").unbind("click").click(function(){
    				router.route("capitalManage/pledgeEvaluationSheet.html");
    			});
    			
    			$("#lendUint-manager").unbind("click").click(function(){
    				router.route("lendUnitInfoManage/lendUnitInfoList.html");
    			});
    			
    			$("#loansMoney-manager").unbind("click").click(function(){
    				router.route("loansMoneyManage/loansMoneyList.html");
    			});
    			
    			$("#useCardType-manager").unbind("click").click(function(){
    				router.route("userCardManage/userCardType.html");
    			});
    			
    			$("#useCard-manager").unbind("click").click(function(){
    				router.route("userCardManage/userCard.html");
    			});
    			
    			$("#dataSource-manager").unbind("click").click(function(){
    				router.route("datasource/dataSource.html");
    			});
    			
    			$("#commissionGrade-manager").unbind("click").click(function(){
    				router.route("commissionGrade/commissionGrade.html");
    			});
    			
    			$("#financeNorm-manager").unbind("click").click(function(){
    				router.route("financeNorm/financeNorm.html");
    			});
    			
    			$("#pickFiles").unbind("click").click(function(){
    				router.route("financeNorm/financePickNorm.html");
    			});
    			
    			$("#logisticsCompany-manager").unbind("click").click(function(){
    				router.route("logisticsCompanyManage/logisticsCompanyManage.html");
    			});
    			break;
    		case 4:
    			$("#commodityPriceCollection").unbind("click").click(function(){
    				router.route("commodityPriceCollection/commodityPriceCollectionList.html");
    			});
    			
    			$("#bulkstockManage1").unbind("click").click(function(){
    				router.route("bulkstockManage/bulkstockManage.html");
    			});
    			break;
    		case 5:
    			$(".temporaryAduitList").unbind("click").click(function(){
    				router.route("client/temporaryCreditlineAudit.html");
    			});
    			
    			$(".crmManage").unbind("click").click(function(){
    				var userName = base.getData("userName") + "@zjjr56";
    				location.href="http://122.152.210.195:8099/crm/register?userName=" + userName;
    			});
    			
    			$(".settlementOverdue").unbind("click").click(function(){
    				router.route("client/settlementOverdue.html");
    			});
    			
    			$(".financeServiceSettlement").unbind("click").click(function(){
    				router.route("client/financeServiceSettlement.html");
    			});
    			break;
    		case 6:
	    		//放款单查询
				$(".loanNoticeList").unbind("click").click(function() {
					location.href = "../financing/loanNoticeList.html";
				});
				//放货查询
				$(".deliveryNoticeList").unbind("click").click(function() {
					location.href = "../financing/deliveryNoticeList.html";
				});
				//收款单查询
				$(".receivableNoticeList").unbind("click").click(function() {
					location.href = "../financing/receivableNoticeList.html";
				});
				//已完成融资
				$(".endFinanceList").unbind("click").click(function() {
					location.href = "../financing/endFinanceList.html";
				});
				//收货通知查询
				$(".recieveNoticeList").unbind("click").click(function(){
				location.href="../financing/recieveNoticeList.html";
				});
				//左侧菜单栏	解除监管
				$(".cancelSuperviseA").unbind("click").click(function() {
					router.route("main/supervisionRelieveList.html?left=12", true);
				});
		
				//左侧菜单栏	待审批
				$(".financeUnexamA").unbind("click").click(function() {
					router.route("main/main_finance.html?left=0&financeState=1", true);
				});
		
				//左侧菜单栏	协议上传
				$(".contractUnsignA").unbind("click").click(function() {
					router.route("main/main_finance.html?left=1&financeState=3&contractType=1", true);
				});
		
				//左侧菜单栏	收货通知
				$(".noticeReceiveA").unbind("click").click(function() {
					router.route("main/main_finance.html?left=2&financeState=5", true);
				});
				
				//左侧菜单栏	合同上传
				$(".contractUnsignA11").unbind("click").click(function() {
					router.route("main/main_finance.html?left=5&financeState=3&contractType=2", true);
				});
				
				//左侧菜单栏	合同签署
				$(".contractUnsignA21").unbind("click").click(function() {
					router.route("main/main_finance.html?left=6&financeState=3&contractType=3", true);
				});
		
				//左侧菜单栏 放款申请
				$(".financeUnreleaseA").unbind("click").click(function() {
					router.route("main/loanNotice_list.html?left=7", true);
				});
		
				//左侧菜单栏  放货通知
				$(".financeUnreceiveBulkstockA").unbind("click").click(function() {
					router.route("main/deliveryNotice_list.html?left=11", true);
				});
		
				//左侧菜单栏 收款确认
				$(".financeUnreceiveA").unbind("click").click(function() {
					router.route("main/receivablesNotice_list.html?left=10", true);
				});
		
				//左侧菜单栏 通知运输
				$(".financeUntransportA").unbind("click").click(function() {
					router.route("main/transportNotice_list.html?left=8", true);
				});
		
				//左侧菜单栏 提货审批
				$(".financePickupExamA").unbind("click").click(function() {
					router.route("main/pickupList.html?left=9", true);
				});
		
				//左侧菜单栏 监管确认
				$(".financeUnsuperviseA").unbind("click").click(function() {
					router.route("main/supervisionNotice_list.html?left=3", true);
				});
		
				//左侧菜单栏 延期计息
				$(".interestDelayA").unbind("click").click(function() {
					router.route("main/interestDelayList.html?left=13", true);
				});
		
				//左侧菜单栏 延期还款
				$(".pickupDelayA").unbind("click").click(function() {
					router.route("main/pickupDelayList.html?left=11", true);
				});
		
				//左侧菜单栏 提前还款
				$(".pickupPreA").unbind("click").click(function() {
					router.route("main/pickupPreList.html?left=11", true);
				});
		
				//左侧菜单栏 赎货申请
				$(".pickupRansomA").unbind("click").click(function() {
					router.route("main/pickupRansomList.html?left=15", true);
				});
		
				//左侧菜单栏 扣货申请
				$(".detainedA").unbind("click").click(function() {
					router.route("main/detainedList.html?left=14", true);
				});
		
				//左侧菜单栏 扣货申请
				$(".badassetsHandleA").unbind("click").click(function() {
					router.route("main/badassetsHandleList.html?left=16", true);
				});
		
				//左侧菜单栏 异常管理
				$(".abnormalManageA").unbind("click").click(function() {
					location.href = "../exception/exceptionManage.html";
				});
    			break;
    		case 7:
				//左侧菜单栏	待审批
				$(".financeUnexamA").unbind("click").click(function() {
					router.route("main/main_finance.html?left=0&financeState=1", true);
				});
		
				//左侧菜单栏	协议上传
				$(".contractUnsignA").unbind("click").click(function() {
					router.route("main/main_finance.html?left=1&financeState=3&contractType=1", true);
				});
				
				//左侧菜单栏	通知锁定
				$(".noticeReceiveA").unbind("click").click(function() {
					router.route("main/main_finance.html?left=2&financeState=5", true);
				});
				
				//左侧菜单栏	协议上传
//				$(".contractUnsignA1").unbind("click").click(function() {
//					router.route("main/main_finance.html?left=1&financeState=3&contractType=2", true);
//				});
				
				//左侧菜单栏 监管确认
				$(".financeUnsuperviseA").unbind("click").click(function() {
					router.route("main/supervisionNotice_list.html?left=3", true);
				});
				
				//左侧菜单栏	合同上传
				$(".contractUnsignA11").unbind("click").click(function() {
					router.route("main/main_finance.html?left=4&financeState=3&contractType=2", true);
				});
				
				//左侧菜单栏	合同签署
				$(".contractUnsignA21").unbind("click").click(function() {
					router.route("main/main_finance.html?left=5&financeState=3&contractType=3", true);
				});
		
				//左侧菜单栏	待审批
				$(".financeUnexam1").unbind("click").click(function() {
					router.route("main/main_finance.html?left=6&financeState=23", true);
				});
		
				//左侧菜单栏 放款申请
				$(".financeUnreleaseA").unbind("click").click(function() {
					router.route("main/loanNotice_list.html?left=7", true);
				});
				
				//左侧菜单栏 放款审核
				$(".financeUnloanA").unbind("click").click(function() {
					router.route("main/loanNoticeList.html");
				});
				
				//点击增补合同
				$(".supplementContractA").unbind("click").click(function() {
					router.route("main/main_finance.html?left=9&financeState=31&contractType=4", true);
				});
		
				//左侧菜单栏 通知运输
				$(".financeUntransportA").unbind("click").click(function() {
					router.route("main/transportNotice_list.html?left=10", true);
				});
		
				//左侧菜单栏 提货审批
				$(".financePickupExamA").unbind("click").click(function() {
					router.route("main/pickupList.html?left=11", true);
				});
				
				//左侧菜单栏 收款确认
				$(".financeUnreceiveA").unbind("click").click(function() {
					router.route("main/receivablesNotice_list.html?left=12", true);
				});
				
				//左侧菜单栏  放货通知
				$(".financeUnreceiveBulkstockA").unbind("click").click(function() {
					router.route("main/deliveryNotice_list.html?left=13", true);
				});
				
				//左侧菜单栏	解除监管
				$(".cancelSuperviseA").unbind("click").click(function() {
					router.route("main/supervisionRelieveList.html?left=14", true);
				});
				
				//-----------------------------------------------------------
				
				//左侧菜单栏 提前还款
				$(".pickupPreA").unbind("click").click(function() {
					router.route("main/pickupPreList.html?left=11", true);
				});
				
				//左侧菜单栏 延期计息
				$(".interestDelayA").unbind("click").click(function() {
					router.route("main/interestDelayList.html?left=12", true);
				});
		
				//左侧菜单栏 延期还款
				$(".pickupDelayA").unbind("click").click(function() {
					router.route("main/pickupDelayList.html?left=12", true);
				});
		
				//左侧菜单栏 扣货申请
				$(".detainedA").unbind("click").click(function() {
					router.route("main/detainedList.html?left=13", true);
				});
				
				//左侧菜单栏 赎货申请
				$(".pickupRansomA").unbind("click").click(function() {
					router.route("main/pickupRansomList.html?left=14", true);
				});
		
				//左侧菜单栏 扣货申请
				$(".badassetsHandleA").unbind("click").click(function() {
					router.route("main/badassetsHandleList.html?left=15", true);
				});
		
				//左侧菜单栏 异常管理
				$(".abnormalManageA").unbind("click").click(function() {
					location.href = "../exception/exceptionManage.html";
				});
    			break;
    		case 8:
    			break;
    		case 9:
    			break;
    		case 10:
				//风险预警	
    			$(".riskWarning").unbind("click").click(function(){
    				router.route("auditWarning/riskWarning.html");
    			});
    			
    			//审批预警
    			$(".auditWarning").unbind("click").click(function(){
    				router.route("auditWarning/auditWarning.html");
    			});
    			
    			//预警方案
    			$(".warningScheme").unbind("click").click(function(){
    				router.route("auditWarning/warningSchemeList.html");
    			});
    			
    			//融资预警
    			$(".warningSchemeResult").unbind("click").click(function(){
    				router.route("auditWarning/warningSchemeResultList.html");
    			});
    			
    			//融资预警1
    			$(".warningSchemeResult1").unbind("click").click(function(){
    				router.route("auditWarning/warningSchemeResultList1.html");
    			});
    			
    			//风险预警-已解决	
    			$(".riskWarningSettled").unbind("click").click(function(){
    				router.route("auditWarning/riskWarning.html?settled=true");
    			});
    			
    			//融资预警-已解决
    			$(".warningSchemeResultSettled").unbind("click").click(function(){
    				router.route("auditWarning/warningSchemeResultList.html?settled=true");
    			});
    			break;
    		case 11:
    			//临时额度审核
    			$(".temporaryAduitList").unbind("click").click(function(){
    				router.route("client/temporaryCreditlineAudit.html");
    			});
    			
    			//用户列表
    			$(".memberGradeAduitList").unbind("click").click(function(){
					router.route("client/memberGradeaudit.html");
				});
				
				//业务申请
				$(".financeApplicationList").unbind("click").click(function(){
					router.route("creditManage/financeApplicationList.html");
				});
				
				//代采业务申请
				$(".agencyPurchasing").unbind("click").click(function(){
					router.route("creditManage/applyMain2.html");
				});
				
				//代销业务申请
				$(".agencySales").unbind("click").click(function(){
					router.route("creditManage/applyMain1.html");
				});
				
				//合同审核
				$(".contractUnsignA").unbind("click").click(function() {
					router.route("main/main_finance.html?left=1&financeState=3");
				});
				
				//货品维护
				$(".bulkstockManage1").unbind("click").click(function(){
    				router.route("commodityPriceCollection/commodityPriceCollectionList.html");
    			});
    			
    			//价格维护
    			$(".commodityPriceCollection").unbind("click").click(function(){
    				router.route("bulkstockManage/bulkstockManage.html");
    			});
    			
    			//货值预警
    			$(".warningScheme").unbind("click").click(function(){
    				router.route("auditWarning/warningSchemeList.html");
    			});
    			break;
    		case 12:
    			//仓储类型提货列表-所有
    			$("#leftMenu12 .warehousePickApplicationAll").unbind("click").click(function(){
    				router.route("warehousePickup/wareHousePickupList.html");
    			});
    			//仓储类型提货列表
    			$("#leftMenu12 .warehousePickApplication").unbind("click").click(function(){
    				router.route("warehousePickup/wareHousePickupList.html?pickupState=0");
    			});
    			
    			//代销提货
    			$("#leftMenu12 .salePickApplication").unbind("click").click(function(){
    				router.route("warehousePickup/createPickup.html");
    			});
    			
    			//代采提货
    			$("#leftMenu12 .purchasePickApplication").unbind("click").click(function(){
    				router.route("warehousePickup/createPickup1.html");
    			});
    			
    			//仓储类型提货列表-合同上传
    			$("#leftMenu12 .warehousePickApplicationUpload").unbind("click").click(function(){
    				router.route("warehousePickup/wareHousePickupList.html?pickupState=[3, 4, 5, 7, 8]");
    			});
    			
    			//仓储类型提货列表-合同签署
    			$("#leftMenu12 .warehousePickApplicationSign").unbind("click").click(function(){
    				router.route("warehousePickup/wareHousePickupList.html?pickupState=6");
    			});
    			
    			//仓储类型提货列表-提货初审
    			$("#leftMenu12 .warehousePickApplicationFirst").unbind("click").click(function(){
    				router.route("warehousePickup/wareHousePickupList.html?pickupState=2");
    			});
    			
    			//仓储类型提货列表-提货政审
    			$("#leftMenu12 .warehousePickApplicationSecond").unbind("click").click(function(){
    				router.route("warehousePickup/wareHousePickupList.html?pickupState=10");
    			});
    			
    			//仓储类型提货列表-提货处理
    			$("#leftMenu12 .operateWarehousePickApplication").unbind("click").click(function(){
    				router.route("warehousePickup/wareHousePickupList.html?pickupState=[11]");
    			});
    		default:
    			break;
    	}
    }
    
    //权限控制
    var inquireCurrentOperationList = function(){
        base.fnAjax({
            action: 'inquireCurrentOperationList.json',
            async:false,
            fnSuccess: function (data) {
                if (data.status == 200) {
                    for(var i=0;i<data.datas.length;i++){
                        var permission = data.datas[i];
                        var permissionId = permission.permissionId;
                        $.each($("#leftMenu").find("li,a"), function() {
                        	var $this = $(this);
                        	if($this.attr("permissionId") == permissionId){
                        		$this.removeClass("none");
                        	}
                        });
                    }
                } else {
                    base.alert(3, data.message);
                }
            }
        });
    };
    return {
        init:init
    }
});

